#include "Matrix3x3.h"

Matrix3x3::Matrix3x3() : Matrix<3>()
{
}

Matrix3x3::Matrix3x3(const Matrix3x3& copy) : Matrix<3>(copy)
{
	
}

Matrix3x3::~Matrix3x3()
{
}

Matrix3x3& Matrix3x3::scale(const float sx, const float sy, const float sz)
{
	m[0][0] = sx;
	m[0][1] = 0;
	m[0][2] = 0;
	m[1][0] = 0;
	m[1][1] = sy;
	m[1][2] = 0;
	m[2][0] = 0;
	m[2][1] = 0;
	m[2][2] = sz;

	return *this;
}

Matrix3x3& Matrix3x3::rotateX(const float alpha)
{
	const float cosa = cos(alpha), sina = sin(alpha);

	m[0][0] =     1; m[0][1] =     0; m[0][2] =     0;
			m[1][0] =     0; m[1][1] =  cosa; m[1][2] = -sina;
			m[2][0] =     0; m[2][1] =  sina; m[2][2] =  cosa;

	return *this;
}

Matrix3x3& Matrix3x3::rotateY(const float alpha)
{
	const float cosa = cos(alpha), sina = sin(alpha);

	m[0][0] =  cosa; m[0][1] =     0; m[0][2] =  sina;
			m[1][0] =     0; m[1][1] =     1; m[1][2] =     0;
			m[2][0] = -sina; m[2][1] =     0; m[2][2] =  cosa;

	return *this;
}

Matrix3x3& Matrix3x3::rotateZ(const float alpha)
{
	const float cosa = cos(alpha), sina = sin(alpha);

	m[0][0] =  cosa; m[0][1] = -sina; m[0][2] =     0;
				m[1][0] =  sina; m[1][1] =  cosa; m[1][2] =     0;
				m[2][0] =     0; m[2][1] =     0; m[2][2] =     1;

	return *this;
}

void Matrix3x3::transformVector(const Vector& in, Vector& out) const
{
	const float _x = in.x, _y = in.y, _z = in.z;

	out.x = m[0][0]*_x + m[0][1]*_y + m[0][2]*_z;
	out.y = m[1][0]*_x + m[1][1]*_y + m[1][2]*_z;
	out.z = m[2][0]*_x + m[2][1]*_y + m[2][2]*_z;
}
